package test;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

interface IntegerStack {
	public Integer push(Integer item);
	public Integer pop(); 
	public Integer peek(); 
	public boolean empty(); 
	public int size(); 

}
class ArrayListIntegerStack implements IntegerStack {
	private List<Integer>list;
	
	public ArrayListIntegerStack(){
		list = new ArrayList<Integer>();
	}
	
	
	@Override
	public String toString() {
		return list.toString();
	}


	@Override
	public Integer push(Integer item) {
		if(item==null)
			return null;
		list.add(item);
			return item;
	}

	@Override
	public Integer pop() {
		if(list.isEmpty())
			return null;
		return list.remove(list.size()-1);
			
	}

	@Override
	public Integer peek() {
		if(list.isEmpty())
			return null;
		return list.get(list.size()-1);
	}

	@Override
	public boolean empty() {
		return list.isEmpty();
	}

	@Override
	public int size() {
		return list.size();
	}
}

public class Main0501 {
	public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int m=in.nextInt();
        IntegerStack stack=new ArrayListIntegerStack();
        for(int i = 0;i<m;i++){
        	System.out.println(stack.push(in.nextInt()));
        }
        System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
        System.out.println(stack.toString());
        int x=in.nextInt();
        for(int j = 0;j<x;j++){
        	System.out.println(stack.pop());
        }
        System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
        System.out.println(stack.toString());
        in.close();
	}
}
